package com.dragon.mmochat.message;

import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.bet.MmochatBet;
import com.dragon.mmochat.model.bet.MmochatBetInfo;
import com.dragon.mmochat.model.bet.MmochatBetPathSection;
import com.dragon.mmochat.model.bet.MmochatBetRate;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_17_7S extends SkymobiProtocolMessage {
	private MmochatBet bet;
	private MmochatPlayer me;
	private int moneyAward;
	private List<MmochatBetPathSection> pathSections;

	public Mmochat_17_7S() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_17_7);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		// 赌场类型
		out.put((byte) bet.getBetType().getKey());
		// 参赛动物数
		out.put((byte) pathSections.size());
		for (MmochatBetPathSection pathInfo : pathSections) {
			// 动物索引
			out.put((byte) pathInfo.getIndex());
			// 分段数
			out.put((byte) pathInfo.getPathList().size());
			// 路程组
			for (Integer pathLen : pathInfo.getPathList()) {
				out.putInt(pathLen);
			}
			// 时间组
			for (Integer timeLen : pathInfo.getTimeList()) {
				out.putInt(timeLen);
			}
			// 赢的钱数
			MmochatBetInfo betInfo = bet.getBetMap().get(me.getRoleId());
			if (betInfo == null) {
				out.putInt(0);
			} else {
				// 压注金额
				Integer money = betInfo.getBetMoneyMap().get(
						pathInfo.getIndex());
				if (money == null){
					money = 0;
				}
				// 赔率
				MmochatBetRate betRate = bet.getBetRates()[pathInfo.getIndex()];
				int award = (int) (betRate.getAward() * money);
				out.putInt(award);
			}
		}
		out.putInt(moneyAward);
	}

	public void setBet(MmochatBet bet) {
		this.bet = bet;
	}

	public void setMe(MmochatPlayer me) {
		this.me = me;
	}

	public void setPathSections(List<MmochatBetPathSection> pathSections) {
		this.pathSections = pathSections;
	}

	public void setMoneyAward(int moneyAward) {
		this.moneyAward = moneyAward;
	}

}
